<template>
  <a-modal title="用户选择" :visible="show" @ok="handleOk" @cancel="handleCancel" width="70vw" :maskClosable="false">
    <div>
      <a-form-model ref="mainForm" layout="inline">
        <a-form-model-item>
          <a-button @click="fetchList">刷新</a-button>
        </a-form-model-item>
      </a-form-model>
    </div>
    <a-table
      :columns="columns"
      :data-source="records"
      rowKey="id"
      bordered
      :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
    >
    <span slot="fileName" slot-scope="text, record">
        {{ record.bidFile.fileName+"."+record.bidFile.fileType }}
      </span>
    </a-table>
  </a-modal>
</template>

<script>
import { getAction, postAction } from '@/api/manage'

export default {
  props: {
    show: {
      type: Boolean,
      default: false,
    },
    contractId: {
      type: String,
      default: '0',
    },
  },
  data() {
    return {
      columns: [
        {
          title: '所属附件名称',
          dataIndex: 'formName',
          key: 'formName',
        },
        {
          title: '文件名称',
          scopedSlots: { customRender: 'fileName' },
        },
        {
          title: '上传人',
          dataIndex: 'modifyUser',
          key: 'modifyUser',
        },
        ,
        {
          title: '上传时间',
          dataIndex: 'modifyTime',
          key: 'modifyTime',
        },
      ],
      records: [],
      urls: {
        list: '/hte/contract/loadContractAttach',
      },
      currentSelection: [],
      selectedRowKeys: [],
    }
  },
  mounted() {
    this.fetchList()
  },
  methods: {
    init() {
      this.currentSelection = []
      this.selectedRowKeys = []
      this.fetchList()
    },
    async fetchList() {
      let res = await getAction(this.urls.list + '/' + this.contractId, {})
      if (res.success) {
        this.records = res.result
      }
    },
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.currentSelection = selectedRows
    },
    handleOk() {
      this.$emit('selected', this.currentSelection)
    },
    handleCancel(e) {
      this.$emit('selected', [])
    },
  },
}
</script>

<style>
</style> 